package com.TestInterface;

/**
 * @Package: com.TestInterface
 * @ClassName: test
 * @Author: h2cloud
 * @CreateTime: 2023/9/12 11:48 下午
 * @Description:
 */
public class test_instanceof {
	public static class Parent {

	}

	public interface Face {

	}

	public static class Child extends Parent implements Face {

	}

	public static void main(String[] args) {
		Parent p = new Parent();
		Child c = new Child();

		if (c instanceof Parent) {
			System.out.println("实例c 是 Parent 子类");
		}
		if (c instanceof Face) {
			System.out.println("实例c 是 Face 子接口");
		}
		if (c instanceof Child) {
			System.out.println("本身");
		}

		// A.isAssignableFrom(B)
		// B类是A类的子类，或者两个相等
		if (Parent.class.isAssignableFrom(Child.class)) {
			System.out.println("Child.class 是 Parent.class 的子类");
		}
		if (Face.class.isAssignableFrom(Child.class)) {
			System.out.println("Child.class 是 Face.class 的子接口");
		}
		if (Child.class.isAssignableFrom(Child.class)) {
			System.out.println("本身");
		}

		if (Parent.class.isInstance(c)) {
			System.out.println(" Parent 是 实例c 的父类");
		}
		if (Face.class.isInstance(c)) {
			System.out.println(" Face 是 实例c 的父接口");
		}
		if (Child.class.isInstance(c)) {
			System.out.println("本身");
		}
		if (Child.class.isInstance(c)) {
			System.out.println("本身");
		}
	}
}
